﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T4Template.Dto
{
    public class ClassModelDto
    {
        public int Id { get; set; }
        public string Name { get; set; }
        private List<AttributeModelDto> _attributes;

        public ClassModelDto()
        {
            _attributes = new List<AttributeModelDto>();
        }

        public void AddAttribute(AttributeModelDto attribute)
        {
            _attributes.Add(attribute);
        }

        public List<AttributeModelDto> GetAttributes()
        {
            return _attributes;
        }

        public ClassModelDto GetAllPrimaryKey()
        {
            ClassModelDto newDto = new ClassModelDto();
            newDto.Id = this.Id;
            newDto.Name = this.Name;

            List<AttributeModelDto> resultList = _attributes.FindAll(a => a.Pk == true);
            foreach(var item in resultList){
                newDto.AddAttribute(item);
            }

            return newDto;
        }

        public ClassModelDto GetAllSearchable()
        {
            ClassModelDto newDto = new ClassModelDto();
            newDto.Id = this.Id;
            newDto.Name = this.Name;

            List<AttributeModelDto> resultList = _attributes.FindAll(a => a.Search == true);
            foreach (var item in resultList)
            {
                newDto.AddAttribute(item);
            }

            return newDto;
        }

        public ClassModelDto GetAllDisplay()
        {
            ClassModelDto newDto = new ClassModelDto();
            newDto.Id = this.Id;
            newDto.Name = this.Name;

            List<AttributeModelDto> resultList = _attributes.FindAll(a => a.Display == true);
            foreach (var item in resultList)
            {
                newDto.AddAttribute(item);
            }

            return newDto;
        }
    }
}
